/*******************************************************************************
 * Copyright 2007 Vidar Svansson
 *     
 * This file is part of JAdapter.
 * 
 * JAdapter is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * JAdapter is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with JAdapter.  If not, see <http://www.gnu.org/licenses/>.
 *******************************************************************************/


package org.jadapter.tests;

import java.util.HashMap;
import java.util.List;
import java.util.TreeSet;

import org.jadapter.Components;
import org.jadapter.tests.examples.CommaSeparated;
import org.jadapter.tests.examples.CommaSeparatedList;
import org.jadapter.tests.examples.CommaSeparatedMap;

public class TestRegistry extends BaseTestCase {
    

    public void testComponentRegistry() throws Exception {
        Components.register(listAdapter);
        Components.register(mapAdapter);
        
        //List<?> adapters = Components.getAdapters();
        //assertEquals("number of adapters", 2, adapters.size());
        
        Object o1 = Components.get(CommaSeparated.class, list);
        assertTrue("list adapter", o1 instanceof CommaSeparatedList);
        
        
        Object o2 = Components.get(CommaSeparated.class, map);
        assertTrue("map adapter", o2 instanceof CommaSeparatedMap); 
        
        Object o3 = Components.get(List.class, new HashMap());
        assertNull("no adapters for HashMap->List", o3);
        
        Object o4 = Components.get(CommaSeparated.class, new TreeSet());
        assertNull("no adapters for TreeSet->CommaSeparated", o4);  
    }
    
    public void testGenericComponentRegistry() throws Exception {
        Components.register(listAdapter);
        Components.register(mapAdapter);
        
        //List<?> adapters = Components.getAdapters();
        //assertEquals("number of adapters", 2, adapters.size());
        
        CommaSeparated o1 = Components.get(CommaSeparated.class, list);
        assertTrue("list adapter", o1 instanceof CommaSeparatedList);
        
        
        CommaSeparated o2 = Components.get(CommaSeparated.class, map);
        assertTrue("map adapter", o2 instanceof CommaSeparatedMap); 
        
        // this is not possible since get() is typesafe
        // CommaSeparated o3 = Components.get(List.class, new HashMap());
        
        CommaSeparated o4 = Components.get(CommaSeparated.class, new TreeSet());
        assertNull("no adapters for TreeSet->CommaSeparated", o4);      
    }
    

}
